package servlet;

import com.alibaba.fastjson.JSON;
import mapper.Findname;
import model.Test;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/index")
public class indexServlet extends HttpServlet {
    protected void  doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//       浏览器使用 utf-8进行解码
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-Type", "text/html;charset=utf-8");

        String name = request.getParameter("name");
        Findname findname = new Findname();
//        System.out.println(name);
        response.getWriter().write(JSON.toJSONString(findname.NameList(name)));

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("html/index.html").forward(request,response);
    }
}
